package ogdkp.om;

import java.util.ArrayList;
import java.util.List;

public class Player implements ITreeNode {

	final String name;

	final String className;

	final String role;

	final int startingDKP;

	final List<ITreeNode> loot;

	private boolean isRaiding;

	private final int level;

	public Player(final String name, final String className, final String role, final int level, final int currentDKP) {
		this.name = name;
		this.className = className;
		this.role = role;
		this.startingDKP = currentDKP;
		this.level = level;
		loot = new ArrayList<ITreeNode>();
		isRaiding = true;
	}

	public String getName() {
		return name;
	}

	public String getClassName() {
		return className;
	}

	public String getRole() {
		return role;
	}

	public int getLevel() {
		return level;
	}

	public int getCurrentDKP() {
		return startingDKP - getSpentDKP();
	}

	public int getStartingDKP() {
		return startingDKP;
	}

	public int getSpentDKP() {
		int spent = 0;
		for (final ITreeNode item : loot) {
			spent += ((Loot) item).getCost();
		}
		return spent;
	}

	@Override
	public ITreeNode getParent() {
		return null;
	}

	@Override
	public List<ITreeNode> getChildren() {
		return loot;
	}

	public void addLoot(final String name, final int value) {
		loot.add(new Loot(this, name, value));

	}

	public void removeLoot(final Loot toRemove) {
		if (loot.contains(toRemove)) {
			loot.remove(toRemove);
		} else {
			throw new RuntimeException("Item not found!");
		}

	}

	public boolean isRaiding() {
		return isRaiding;
	}

	public void setRaiding(final boolean isRaiding) {
		this.isRaiding = isRaiding;
	}

	public String getRace() {
		return "Human";
	}
}
